package com.edu.zju.scs.panacea.mapper.plan;

import com.edu.zju.scs.panacea.entity.plan.Seller;
import com.edu.zju.scs.panacea.entity.resource.Site;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author: Yue Liang
 * @Date: 2018-12-12 18:43
 */
@Repository
public interface SellerMapper {
    @Select("SELECT * FROM plan_seller WHERE id = #{id}")
    @Results({
            @Result(id=true,property="id",column="id"),
            @Result(property="ownId",column="own_id"),
            @Result(property="name",column="name")})
    Seller selectSeller(Long id);


    @Select("SELECT * FROM plan_seller")
    @Results({
            @Result(id=true,property="id",column="id"),
            @Result(property="ownId",column="own_id"),
            @Result(property="name",column="name")})
    List<Seller> selectAllSeller();

    @Delete("DELETE FROM plan_seller where id = #{id}")
    long deleteSeller(Long id);

    @Insert("INSERT INTO plan_seller(own_id, name, password) VALUES(#{ownId}, #{name}, #{password})")
    @Options(useGeneratedKeys=true)
    long insertSeller(Seller seller);

    @Update({ "update plan_seller set own_id = #{ownId}, name = #{name} where id = #{id}" })
    long updateSeller(Seller seller);

    @Select("SELECT * FROM plan_seller WHERE name = #{name} and password = #{password}")
    @Results({
            @Result(id=true,property="id",column="id"),
            @Result(property="ownId",column="own_id"),
            @Result(property="name",column="name")})
    Seller selectValidSeller(String name, String password);

}
